package com.lanou3g.sockerPractice;

import com.lanou3g.practice.*;

import java.io.*;
import java.net.Socket;

/**
 * Created by dllo on 18/4/21.
 */
public class ServerEchoThread extends Thread {

    private Socket client;

    public ServerEchoThread(Socket client) {
        this.client = client;
    }

    @Override
    public void run() {
        PrintWriter pw = null;
        BufferedReader br= null;
        try {
            InputStream is = client.getInputStream();
            OutputStream os = client.getOutputStream();



            pw = new PrintWriter(new OutputStreamWriter(os));
            br = new BufferedReader(new InputStreamReader(is));

            String line = "";
            while ((line = br.readLine()) != null){

                String echo = "ECHO"+line;

                pw.println(echo);
                pw.flush();

            }

        } catch (Exception e) {

            e.printStackTrace();
        }finally {
            IOUtils.closeAll(pw,br);
        }


    }
}
